package com.vs.meepet.network.ext

import com.vs.meepet.network.base.WrapperData

/**
 *
 * 作者：柯嘉少
 * 邮箱：2449926649@qq.com
 * 日期: 2023/11/1
 * 修改人: xxx(des)
 * 说明: 请求状态流程封装（DSL）
 * 版本: 1.0
 */
class RequestAction<T> {

    // 开始请求
    var start: (() -> Unit)? = null
        private set

    // 发起请求
    var request: (suspend () -> WrapperData<T>)? = null
        private set

    // 请求成功
    var success: ((T?) -> Unit)? = null
        private set

    // 请求失败
    var error: ((String) -> Unit)? = null
        private set
    var errorWithCode: ((Int,String) -> Unit)? = null
        private set

    // 请求结束
    var finish: (() -> Unit)? = null
        private set

    fun request(block: suspend () -> WrapperData<T>) {
        request = block
    }

    fun start(block: () -> Unit) {
        start = block
    }

    fun success(block: (T?) -> Unit) {
        success = block
    }

    fun error(block: (String) -> Unit) {
        error = block
    }

    fun errorWithCode(block: (Int,String) -> Unit) {
        errorWithCode = block
    }

    fun finish(block: () -> Unit) {
        finish = block
    }

}
